Skip to content

For water tracers: Add handling of rank-3 fields and refactor med_phases_prep_glc_map_lnd2glc#634

Open
billsacks wants to merge 8 commits intoESCOMP:mainfrom
billsacks:handle_rank3_fields
Open

For water tracers: Add handling of rank-3 fields and refactor med_phases_prep_glc_map_lnd2glc#634
billsacks wants to merge 8 commits intoESCOMP:mainfrom
billsacks:handle_rank3_fields

Conversation

@billsacks
Copy link
Member

Description of changes

Two sets of changes that will be needed for water tracers - and in particular, for the tracer version of Flgl_qice_elev, which will be the first field in CMEPS that has two ungridded dimensions:

(1) Extend various methods to support rank-3 fields

(2) Refactor med_phases_prep_glc_map_lnd2glc to pre-compute vertical interpolation weights; this will be helpful when we introduce Flgl_qice_elev_wtracers to avoid duplicating this calculation of vertical interpolation weights between the non-tracer (rank-2 on the lnd grid and rank-1 on the glc grid) and tracer (rank-3 on the lnd grid and rank-2 on the glc grid) fields.

Specific notes

Contributors other than yourself, if any: Claude Code did a lot of the writing of this code, but I have reviewed it all carefully

CMEPS Issues Fixed (include github issue #):

Are changes expected to change answers? (specify if bfb, different at roundoff, more substantial) bfb when using #633 as a baseline

Any User Interface Changes (namelist or namelist defaults changes)? No

Testing performed

In the context of cesm3_0_alpha08e, ran:

(1) aux_glc on derecho plus a few extra tests, with comparisons against baselines generated with #633 .

The extra tests beyond aux_glc were:

SMS_Ly2.f09_g17_gris20.T1850Gg.derecho_intel
SMS_Ld5.f10_f10_ais8gris4_mg37.I1850Clm50SpGag.derecho_intel.cism-test_coupling
SMS_Lm13.f10_f10_mg37.I1850Clm50SpG.derecho_intel
ERS_Ld5.ne30pg3_t232.B1850C_LTso.derecho_intel.allactive-decstart
ERS_Ld5.ne30pg3_t232.BHISTC_LTso.derecho_intel.allactive-decstart

All tests passed and were bit-for-bit, except for this failure that also failed in the baseline: FAIL NCK_Ly3.f09_g17_gris20.T1850Gg.derecho_gnu COMPARE_base_multiinst

(2) Full prealpha testing on derecho and izumi with comparison against cesm3_0_alpha08e

Tests passed except for tests that also failed in the baselines or seemed to have passed due to tweaks made in the baseline (e.g., increasing wallclock time for SUB_D_Ln9.ne3pg3_ne3pg3_mt232.FHIST.izumi_nag.cam-outfrq9s).

Baseline failures were all as expected (except that a few B compset tests failed baseline comparison due to a difference in which cpl.hx.ww3 files were present in the run vs. baseline, which presumably is due to something outside of this PR):

ERS_Ld5.ne30pg3_t232.B1850C_LTso.derecho_intel.allactive-decstart
ERS_Ld5.ne30pg3_t232.BHISTC_LTso.derecho_intel.allactive-decstart
ERS_Ly7.f09_g17_gris4.T1850Gg.derecho_intel
MULTINOAIS_Ly2.f10_f10_ais8gris4_mg37.I1850Clm50SpRsGag.derecho_intel.cism-change_params
SMS_Lm13.f10_f10_mg37.I1850Clm50SpG.derecho_intel
SMS_D_Ly1.f09_g17_ais8.T1850Ga.derecho_gnu
SMS_D_Ld5_P24x1.f10_f10_ais8gris4_mg37.I1850Clm50SpGag.izumi_nag.cism-test_coupling

Note that I showed that these differences go away when comparing against baselines generated with #633 , for similar or identical tests.

So I think it's safe to conclude that this is bit-for-bit with #633 .

For code that used to handle 0 or 1 ungridded dimension, add handling of
2 ungridded dimensions. This is needed for fields that already had an
ungridded dimension and now have an additional ungridded dimension for
water tracers - currently just Flgl_qice_elev.

Most of these code changes were written by Claude Code, but reviewed by
myself.
Changes were mostly made by Claude Code, reviewed by myself.
This will be needed for qice_elev water tracers, which will have two
ungridded dimensions (one for elevation class and one for water
tracers).

Code was written by Claude Code, reviewed by myself.
Precompute the vertical interpolation coefficients rather than
recomputing them for each field. The main motivation is to avoid
duplication of this logic when we add water tracer fields.

Code mostly written by Claude Code with significant guidance from me,
reviewed by myself.
@billsacks billsacks requested a review from mvertens February 24, 2026 04:12
@billsacks
Copy link
Member Author

The i/o of fields with 2 ungridded dimensions follows the pattern used for fields with 1 ungridded dimension: For fields with 1 ungridded dimension, a separate variable is written for each level (e.g., lndImp_Flgl_qice_elev1, lndImp_Flgl_qice_elev2, etc.). For fields with 2 ungridded dimensions, a separate variable is written for each combination of levels. So, for example, with 2 water tracers and 11 elevation classes, we'll get 22 variables on the NetCDF file. These are named like lndImp_Flgl_qice_elev_wtracers1_1, lndImp_Flgl_qice_elev_wtracers2_1, lndImp_Flgl_qice_elev_wtracers1_2, lndImp_Flgl_qice_elev_wtracers2_2, lndImp_Flgl_qice_elev_wtracers1_3, etc., where the indices appear in the same order as the ungridded dimensions.

Now that I write that out, I'm realizing that there's something kind of confusing here: in this case, the name of the 'elev' dimension comes before the name of the 'wtracers' dimension, but the index of the 'wtracers' dimension comes before the index of the 'elev' dimension. I don't think I want to change the name: various code relies on '_wtracers' being the final suffix for all water tracer fields. Changing the order of the ungridded dimensions might be a bit more doable, though still isn't appealing to me, since @mvertens and I agreed that it made the most sense to put the water tracer dimension first. Maybe the solution is to add some metadata in the NetCDF file giving the meaning of each of these indices. But I'm not sure how easy that will be to do (without resorting to hard-coding stuff in an ugly way), because I'm not sure if we have that information readily available in any data structures that are accessible in med_io_mod. I haven't dug into this yet... maybe it's easier than I'm imagining... @mvertens I'd be happy to talk more with you about this if you think this feels important....

@mvertens
Copy link
Collaborator

@billsacks - I am wondering if we need to rethink writing separate history fields for each ungridded dimension. I think there was a reason I did it this way for one ungridded dimension - and it was for simplicity. But I don't think this carries over very easily to more than one ungridded dimension. However, this could potentially effect CDEPS when it's trying to ingest this data. Let's chat.

@billsacks
Copy link
Member Author

I am wondering if we need to rethink writing separate history fields for each ungridded dimension. I think there was a reason I did it this way for one ungridded dimension - and it was for simplicity. But I don't think this carries over very easily to more than one ungridded dimension. However, this could potentially effect CDEPS when it's trying to ingest this data. Let's chat.

Sounds good - yes, I'd be very happy to talk this through with you.

One issue I'm running into with thinking about adding metadata on the meaning of the indices is how to get a name associated with a given ungridded dimension. I don't think that's stored in the ESMF Field (though maybe it's settable/accessible somehow that I haven't thought to look... I haven't dug too deeply yet); if it isn't, then we may need to store this information somewhere else (or get an ESMF extension to handle this). It feels like a similar issue would arise with having an extra dimension, at least if we want the dimension to be named meaningfully (something more meaningful than "Flgl_qice_elev_wtracers_dim1" and "Flgl_qice_elev_wtracers_dim2").

@billsacks
Copy link
Member Author

@Katetc - if you'd like to look at the changes to prep_glc_mod that I mentioned to you, they're in this PR. More changes will be coming soon in a separate PR to actually add the water tracers, but this includes the preparatory refactor of the vertical interpolation.

Using strategy 'ours' to ignore changes coming from main (which are from
ESCOMP#633) because they are already
incorporated into this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants